﻿//====================================================================
// Create by Daniel
// file： YCModuleProduct.cs
// project ：YunCMS
// Build time：2006-10-21
// modify:
// description:
// ===================================================================
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using YunCMS.Model;
using YunCMS.IDAL;
//using Utility;

namespace YunCMS.DAL
{
    /// <summary>
    /// Data Access Layer of dbo.YC_Module_Product.
    /// </summary>
    public partial class YCModuleProductDAL : ModuleDAL<YCModuleProduct>, IYCModuleProductDAL
    {
        #region

        /// <summary>
        /// constractor
        /// </summary>
        public YCModuleProductDAL()
        {
        }
        #endregion

        #region QueryString

        protected override string AddQueryStr
        {
            get
            {
                StringBuilder sqlStr = new StringBuilder();
                sqlStr.Append("insert into YC_Module_Product(");
                sqlStr.Append("CategoryID,Title,Keywords,Author,Description,GalleryID,IsHomePage,AddTime,UpdateTime,Access,Hits,IsPopular,ImageUrl,DiggTop,DiggStep,Active,Source,Price,Lang,Content)");
                sqlStr.Append(" values (");
                sqlStr.Append("@CategoryID,@Title,@Keywords,@Author,@Description,@GalleryID,@IsHomePage,getdate(),getdate(),@Access,@Hits,@IsPopular,@ImageUrl,@DiggTop,@DiggStep,@Active,@Source,@Price,@Lang,@Content)");
                sqlStr.Append(";select @@IDENTITY");

                return sqlStr.ToString();
            }
        }

        protected override string UpdateQueryStr
        {
            get
            {
                StringBuilder sqlStr = new StringBuilder();
                sqlStr.Append("update YC_Module_Product set ");
                sqlStr.Append("CategoryID=@CategoryID,Title=@Title,Keywords=@Keywords,Author=@Author,Description=@Description,GalleryID=@GalleryID,IsHomePage=@IsHomePage,UpdateTime=getdate(),Access=@Access,Hits=@Hits,IsPopular=@IsPopular,ImageUrl=@ImageUrl,DiggTop=@DiggTop,DiggStep=@DiggStep,Active=@Active,Source=@Source,Price=@Price,Lang=@Lang,Content=@Content");
                sqlStr.Append(" where ID=@ID");

                return sqlStr.ToString();
            }
        }
        #endregion

        #region -----------Methods-----------       


        protected override string TableName
        {
            get { return "YC_Module_Product"; }
        }

        /// <summary>
        ///Get YCModuleProduct Entity
        /// </summary>
        /// <param name="dr">dr</param>
        /// <returns>YCModuleProduct Entity</returns>
        public override YCModuleProduct PopulateModelFromDr(IDataReader dr)
        {
            YCModuleProduct Obj = base.PopulateModelFromDr(dr);

            Obj.Author = dr["Author"].ToString();
            if ((dr["GalleryID"]) == DBNull.Value) { Obj.GalleryID = null; } else { Obj.GalleryID = Convert.ToInt32(dr["GalleryID"]); }
            Obj.ImageUrl = dr["ImageUrl"].ToString();
            Obj.Source = dr["Source"].ToString();
            if ((dr["Price"]) == DBNull.Value) { Obj.Price = null; } else { Obj.Price = Convert.ToDecimal(dr["Price"]); }

            return Obj;
        }

        protected override List<SqlParameter> GetSelfParams(YCModuleProduct model)
        {
            List<SqlParameter> extParams = new List<SqlParameter>() {
							new SqlParameter("@GalleryID",SqlDbType.Int),
							new SqlParameter("@ImageUrl",SqlDbType.NVarChar),
							new SqlParameter("@Price",SqlDbType.Decimal)
			};


            if (model.GalleryID != null)
                extParams[0].Value = model.GalleryID;
            else
                extParams[0].Value = DBNull.Value;

            if (model.ImageUrl != String.Empty)
                extParams[1].Value = model.ImageUrl;
            else
                extParams[1].Value = DBNull.Value;

            if (model.Price != null)
                extParams[2].Value = model.Price;
            else
                extParams[2].Value = DBNull.Value;

            return extParams;

        }

        #endregion

    }
}




